package com.hundsun.s3.client.web.action;

import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.hundsun.s3.pub.utils.BizSecurity;
import com.hundsun.s3.mrs.service.ContentService;


@Controller
public class ContentAction {
	
	@Autowired
	private ContentService contentService;
	
	@RequestMapping(value="/login.htm", method=RequestMethod.GET)
	public void toLogin(ModelMap mm) {
		mm.put("key1", BizSecurity.key1);
		mm.put("key2", BizSecurity.key2);
		mm.put("key3", BizSecurity.key3);
	}
	
	@RequestMapping(value="/login.htm", method=RequestMethod.POST)
	public String login(HttpServletRequest req, String username, String password) {
		HttpSession session = req.getSession();
		session.setAttribute("id", username);
		session.setAttribute("name", "用户" + username);
		session.setAttribute("uuid", UUID.randomUUID().toString());
		session.setAttribute("wsPort", contentService.getWsPort());
		return "redirect:/index.htm";
	}
	
	@RequestMapping("/index.htm")
	public void index(ModelMap mm, HttpServletRequest req) {
		HttpSession session = req.getSession();
		mm.put("id", session.getAttribute("id"));
		mm.put("name", session.getAttribute("name"));
		mm.put("uuid", session.getAttribute("uuid"));
		mm.put("wsPort", session.getAttribute("wsPort"));
	}
	
}
